home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / Real / realprefs.c < prev    next >
C/C++ Source or Header  |  1997-11-28  |  7KB  |  255 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Miloslaw Smyk
  6.  */
  7.  
  8. #define REVISION "40.3beta"
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/classes.h>
  13. #include <intuition/classusr.h>
  14. #include <intuition/imageclass.h>
  15. #include <intuition/gadgetclass.h>
  16. #include <libraries/gadtools.h>
  17. #include <graphics/displayinfo.h>
  18. #include <graphics/gfxbase.h>
  19. #include <clib/exec_protos.h>
  20. #include <clib/intuition_protos.h>
  21. #include <clib/gadtools_protos.h>
  22. #include <clib/graphics_protos.h>
  23. #include <clib/utility_protos.h>
  24. #include <string.h>
  25. #include <clib/diskfont_protos.h>
  26.  
  27. #include <pragmas/exec_pragmas.h>
  28. #include <pragmas/intuition_pragmas.h>
  29. #include <pragmas/gadtools_pragmas.h>
  30. #include <pragmas/graphics_pragmas.h>
  31. #include <pragmas/utility_pragmas.h>
  32.  
  33. #include <proto/diskfont.h>
  34.  
  35. #include "wfmhcybergfx_key.h"
  36. #include "realprefs.h"
  37.  
  38. extern struct KeyBase *KeyBase;
  39.  
  40. struct Screen         *Scr = NULL;
  41. UBYTE                 *PubScreenName = NULL;
  42. APTR                   VisualInfo = NULL;
  43. struct Window         *RealPrefsWnd = NULL;
  44. struct Gadget         *RealPrefsGList = NULL;
  45. struct IntuiMessage    RealPrefsMsg;
  46. struct Gadget         *RealPrefsGadgets[5];
  47. UWORD                  RealPrefsLeft = 50;
  48. UWORD                  RealPrefsTop = 50;
  49. UWORD                  RealPrefsWidth = 274;
  50. UWORD                  RealPrefsHeight = 59;
  51. UBYTE                 *RealPrefsWdt = (UBYTE *)"wfmhcybergfx_r3d.library";
  52. struct TextAttr       *Font, Attr;
  53. UWORD                  FontX, FontY;
  54. UWORD                  OffX, OffY;
  55. struct TextFont       *RealPrefsFont = NULL;
  56. int public;
  57. extern ULONG AboutBox;
  58.  
  59. UBYTE *Gadget000Labels[] = {
  60.     (UBYTE *)"Floyd-Steinberg",
  61.     (UBYTE *)"Ordered 4x4",
  62.     (UBYTE *)"None",
  63.     NULL };
  64.  
  65. UWORD RealPrefsGTypes[] = {
  66.     CYCLE_KIND,
  67.     BUTTON_KIND,
  68.     BUTTON_KIND,
  69.     BUTTON_KIND,
  70.     CHECKBOX_KIND
  71. };
  72.  
  73. struct NewGadget RealPrefsNGad[] = {
  74.     101, 5, 160, 13, (UBYTE *)"_Dithering", NULL, GD_Gadget00, PLACETEXT_LEFT, NULL, (APTR)Gadget00Clicked,
  75.     13, 41, 77, 13, (UBYTE *)"_Save", NULL, GD_Gadget10, PLACETEXT_IN, NULL, (APTR)Gadget10Clicked,
  76.     184, 41, 77, 13, (UBYTE *)"_Cancel", NULL, GD_Gadget20, PLACETEXT_IN, NULL, (APTR)Gadget20Clicked,
  77.     98, 41, 77, 13, (UBYTE *)"_Use", NULL, GD_Gadget30, PLACETEXT_IN, NULL, (APTR)Gadget30Clicked,
  78.     101, 23, 26, 13, (UBYTE *)"_About box", NULL, GD_Gadget40, PLACETEXT_LEFT, NULL, (APTR)Gadget40Clicked
  79. };
  80.  
  81. ULONG RealPrefsGTags[] = {
  82.     (GTCY_Labels), (ULONG)&Gadget000Labels[ 0 ], (GT_Underscore), '_', (TAG_DONE),
  83.     (GT_Underscore), '_', (TAG_DONE),
  84.     (GT_Underscore), '_', (TAG_DONE),
  85.     (GT_Underscore), '_', (TAG_DONE),
  86.     (GT_Underscore), '_', (GTCB_Checked), TRUE, (GTCB_Scaled), TRUE, (TAG_DONE)
  87. };
  88.  
  89. static UWORD ComputeX( UWORD value )
  90. {
  91.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  92. }
  93.  
  94. static UWORD ComputeY( UWORD value )
  95. {
  96.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  97. }
  98.  
  99. static void ComputeFont( UWORD width, UWORD height )
  100. {
  101.     Forbid();
  102.     Font = &Attr;
  103.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  104.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  105.     FontX = GfxBase->DefaultFont->tf_XSize;
  106.     Permit();
  107.  
  108.     OffX = Scr->WBorLeft;
  109.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  110.  
  111.     if ( width && height ) {
  112.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  113.             goto UseTopaz;
  114.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  115.             goto UseTopaz;
  116.     }
  117.     return;
  118.  
  119. UseTopaz:
  120.     Font->ta_Name = (STRPTR)"topaz.font";
  121.     FontX = FontY = Font->ta_YSize = 8;
  122. }
  123.  
  124. int SetupScreen(struct Screen *scr)
  125. {
  126.     if(scr)
  127.     {
  128.         Scr = scr;
  129.         public = FALSE;
  130.     }
  131.     else
  132.     {
  133.         public = TRUE;
  134.         if ( ! ( Scr = LockPubScreen( PubScreenName )))
  135.             return( 1L );
  136.         
  137.     }
  138.  
  139.     ComputeFont( 0, 0 );
  140.  
  141.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  142.         return( 2L );
  143.  
  144.     return( 0L );
  145. }
  146.  
  147. void CloseDownScreen( void )
  148. {
  149.     if ( VisualInfo ) {
  150.         FreeVisualInfo( VisualInfo );
  151.         VisualInfo = NULL;
  152.     }
  153.  
  154.     if(Scr && public)
  155.         UnlockPubScreen(NULL, Scr);
  156.  
  157.     Scr = NULL;
  158. }
  159.  
  160. void RealPrefsRender( void )
  161. {
  162.     ComputeFont( RealPrefsWidth, RealPrefsHeight );
  163.  
  164.     DrawBevelBox( RealPrefsWnd->RPort, OffX + ComputeX( 0 ),
  165.                     OffY + ComputeY( 0 ),
  166.                     ComputeX( 274 ),
  167.                     ComputeY( 59 ),
  168.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  169. }
  170.  
  171.  
  172. int OpenRealPrefsWindow( void )
  173. {
  174.     struct NewGadget    ng;
  175.     struct Gadget    *g;
  176.     UWORD        lc, tc;
  177.     UWORD        wleft = RealPrefsLeft, wtop = RealPrefsTop, ww, wh;
  178.  
  179.     ComputeFont( RealPrefsWidth, RealPrefsHeight );
  180.  
  181.     ww = ComputeX( RealPrefsWidth );
  182.     wh = ComputeY( RealPrefsHeight );
  183.  
  184.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  185.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  186.  
  187.     if ( ! ( RealPrefsFont = OpenDiskFont( Font )))
  188.         return( 5L );
  189.  
  190.     if ( ! ( g = CreateContext( &RealPrefsGList )))
  191.         return( 1L );
  192.  
  193.     for( lc = 0, tc = 0; lc < RealPrefs_CNT; lc++ ) {
  194.  
  195.         CopyMem((char * )&RealPrefsNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  196.  
  197.         ng.ng_VisualInfo = VisualInfo;
  198.         ng.ng_TextAttr   = Font;
  199.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  200.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  201.         ng.ng_Width      = ComputeX( ng.ng_Width );
  202.         ng.ng_Height     = ComputeY( ng.ng_Height);
  203.  
  204.         RealPrefsGadgets[ lc ] = g = CreateGadgetA((ULONG)RealPrefsGTypes[ lc ], g, &ng, ( struct TagItem * )&RealPrefsGTags[ tc ] );
  205.  
  206.         while( RealPrefsGTags[ tc ] ) tc += 2;
  207.         tc++;
  208.  
  209.         if ( NOT g )
  210.             return( 2L );
  211.     }
  212.  
  213.     GT_SetGadgetAttrs(RealPrefsGadgets[0], RealPrefsWnd, NULL, GTCY_Active, KeyBase ? KeyBase->dither_type : DT_NONE);
  214.     GT_SetGadgetAttrs(RealPrefsGadgets[4], RealPrefsWnd, NULL, GTCB_Checked, AboutBox);
  215.  
  216.     if ( ! ( RealPrefsWnd = OpenWindowTags( NULL,
  217.                 WA_Left,    wleft,
  218.                 WA_Top,        wtop,
  219.                 WA_Width,    ww + OffX + Scr->WBorRight,
  220.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  221.                 WA_IDCMP,    CYCLEIDCMP|BUTTONIDCMP|CHECKBOXIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_CHANGEWINDOW|IDCMP_VANILLAKEY,
  222.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  223.                 WA_Gadgets,    RealPrefsGList,
  224.                 WA_Title,    RealPrefsWdt,
  225.                 WA_ScreenTitle,    "wfmhcybergfx_r3d.library " REVISION " ©1995-97 Miloslaw Smyk (thorgal@amiga.com.pl)",
  226.                 WA_PubScreen,    Scr,
  227.                 TAG_DONE )))
  228.     return( 4L );
  229.  
  230.     GT_RefreshWindow( RealPrefsWnd, NULL );
  231.  
  232.     RealPrefsRender();
  233.  
  234.     return( 0L );
  235. }
  236.  
  237. void CloseRealPrefsWindow( void )
  238. {
  239.     if ( RealPrefsWnd        ) {
  240.         CloseWindow( RealPrefsWnd );
  241.         RealPrefsWnd = NULL;
  242.     }
  243.  
  244.     if ( RealPrefsGList      ) {
  245.         FreeGadgets( RealPrefsGList );
  246.         RealPrefsGList = NULL;
  247.     }
  248.  
  249.     if ( RealPrefsFont ) {
  250.         CloseFont( RealPrefsFont );
  251.         RealPrefsFont = NULL;
  252.     }
  253. }
  254.  
  255.